from selenium.webdriver.common.by import By
from frp_page_object.base_page import BasePage


class MenuPage(BasePage):

    def click_sales_orders(self):
        self.__select_menu(['订单管理', '2B订单管理', '销售订单'])

    def click_pre_oc_order(self):
        self.__select_menu(['订单管理', '预占管理', '预占单'])

    def click_retail_channel_order(self):
        self.__select_menu(['订单管理', '2C订单管理', '零售原始订单'])

    def click_retail_order(self):
        self.__select_menu(['订单管理', '2C订单管理', '零售订单'])

    def click_cmp(self):
        self.__select_menu(['履约管理', '2C履约计划', '零售履约计划单'])

    def click_delivery_notices(self):
        self.__select_menu(['库存管理', '2C配送管理', '配送通知单'])

    def __select_menu(self, menu_text=None):
        if menu_text is not None:
            self.click((By.XPATH, f'//*[contains(text(),"{menu_text[0]}")]/../..'))
            self.click((By.XPATH, f'//*[contains(text(),"{menu_text[1]}")]/../..'))
            self.click((By.XPATH, f'//*[contains(text(),"{menu_text[2]}")]/../..'))
            self.click((By.XPATH, f'//*[contains(text(),"{menu_text[1]}")]/../..'))
            self.click((By.XPATH, f'//*[contains(text(),"{menu_text[0]}")]/../..'))
